/**
 * 
 */
package br.ufpr.inf.jobtuner.pso.mod;


/**
 * @author Evaristo
 * 
 * Class that implements a Particle to PSO algorithm
 */
public class PSOParticle {
	private double fitness = Double.NEGATIVE_INFINITY;
	private double personalBestFitness = Double.NEGATIVE_INFINITY;
	
	private double[] position = null;
	private double[] personalBestPosition = null;
	private double[] velocity = null;
	
	private int dimentions = 2;

	public PSOParticle(int dimentions) {
		this.dimentions = dimentions;
		initializeDimentions();
	}

	private void initializeDimentions() {
		position = new double[dimentions];
		velocity = new double[dimentions];
	}

	public int getDimentions() {
		return dimentions;
	}
	
	public double getFitness() {
		return fitness;
	}

	public void setFitness(double fitness) {
		this.fitness = fitness;
	}

	public double getPersonalBestFitness() {
		return personalBestFitness;
	}

	public void setPersonalBestFitness(double personalBestFitness) {
		this.personalBestFitness = personalBestFitness;
	}

	public double[] getPosition() {
		return position;
	}

	public void setPosition(double[] position) {
		this.position = position;
	}

	public double[] getPersonalBestPosition() {
		return personalBestPosition;
	}

	public void setPersonalBestPosition(double[] personalBestPosition) {
		this.personalBestPosition = personalBestPosition;
	}

	public double[] getVelocity() {
		return velocity;
	}

	public void setVelocity(double[] velocity) {
		this.velocity = velocity;
	}
	
	public void caculateFitness(){
		this.fitness = PSOFitness.calculate(this);
	}
	
	public void updatePersonalBest(){
		if(this.personalBestFitness < this.fitness){
			this.personalBestFitness = this.fitness;
			personalBestPosition = this.position.clone();
		}
	}
}
